package cn.ncupyh.soft;

import java.util.Random;

public class BoyFriendTest {
    public static void main(String[] args) {
        String[] hobbys ={"打篮球","唱歌","做饭","赚钱","画画","科研","写作","IT"};
        BoyFriend[] arr = new  BoyFriend[4];

        Random r = new Random();
        int i0= r.nextInt(hobbys.length);
        int i1 = r.nextInt(hobbys.length);
        int i2 = r.nextInt(hobbys.length);
        int i3 = r.nextInt(hobbys.length);

        BoyFriend f1 = new BoyFriend("李钟硕",25,"男",hobbys[i0]);
        BoyFriend f2 = new BoyFriend("王俊凯",23,"男",hobbys[i1]);
        BoyFriend f3 = new BoyFriend("易烊千玺",20,"男",hobbys[i2]);
        BoyFriend f4 = new BoyFriend("胡歌",40,"男",hobbys[i3]);

//        赋值
        arr[0] = f1;
        arr[1] = f2;
        arr[2] = f3;
        arr[3] = f4;

        double aver = 0;
        for (int j = 0; j < arr.length; j++) {
            aver += arr[j].getAge();
        }
        aver /= arr.length;
        System.out.println("平均年龄为:" + aver);

//       求比平均年龄小的个数
        int amount = 0;
        for (int j = 0; j < arr.length; j++) {
            if(arr[j].getAge() < aver){
                amount ++;
            }
        }
        System.out.println("比平均年龄小的有" + amount + "个");

//        打印个人信息
        for (int j = 0; j < arr.length; j++) {
            if(arr[j].getAge() < aver){
                BoyFriend ren = arr[j];
                System.out.println(ren.getName() + "," + ren.getAge() + "," +ren.getGender() + "," + ren.getHobby());
            }
        }
    }
}
